{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "e:\\python\\lib\\site-packages\\numpy\\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:\n",
      "e:\\python\\lib\\site-packages\\numpy\\.libs\\libopenblas.XWYDX2IKJW2NMTWSFYNGFUWKQU3LYTCZ.gfortran-win_amd64.dll\n",
      "e:\\python\\lib\\site-packages\\numpy\\.libs\\libopenblas64__v0.3.21-gcc_10_3_0.dll\n",
      "  warnings.warn(\"loaded more than 1 DLL from .libs:\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import sys\n",
    "sys.path.append(\"../../../teddy-cup\")\n",
    "from Utils.utils import *\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "HelloWorld()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "Job_ = pd.read_csv(\"../../Data/ProcessData/Job.csv\")\n",
    "JobDetail_ = pd.read_csv(\"../../Data/ProcessData/JobDetail.csv\")\n",
    "Company_ = pd.read_csv(\"../../Data/ProcessData/CompanyDetail.csv\")\n",
    "People_ = pd.read_csv(\"../../Data/ProcessData/People.csv\")\n",
    "PeopleDetail_ = pd.read_csv(\"../../Data/ProcessData/PeopleDetail.csv\")\n",
    "Job = Job_.merge(JobDetail_).merge(Company_)                                    # 直接合并，防止后续ID的顺序变得混乱\n",
    "People = People_.merge(PeopleDetail_)          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "res1 = np.load(\"res1.npz\")['arr_0']\n",
    "res2 = np.load(\"res2.npz\")['arr_0']\n",
    "res3 = np.load(\"res3.npz\")['arr_0']\n",
    "res4 = np.load(\"res4.npz\")['arr_0']\n",
    "res5 = np.load(\"short.npz\")['arr_0']\n",
    "res_area = np.load(\"res_area.npz\")['arr_0']\n",
    "res_edu = np.load(\"res_edu.npz\")['arr_0']\n",
    "res_exp = np.load(\"res_exp.npz\")[\"arr_0\"]\n",
    "res_pos = np.load(\"res_pos.npz\")['arr_0']\n",
    "res_salary = np.load(\"res_salary.npz\")['arr_0']\n",
    "res_willnature = np.load(\"res_willnature.npz\")['arr_0']"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "有inf就代表是绝对指标，最终匹配度就会是0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_willnature[res_willnature==1] = 0\n",
    "ArrContainValue(res_willnature,-np.inf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[      -inf,       -inf,       -inf, ...,       -inf,       -inf,\n",
       "              -inf],\n",
       "       [0.71997078,       -inf, 0.8207153 , ..., 0.5100468 , 0.5100468 ,\n",
       "        0.5100468 ],\n",
       "       [0.71868782,       -inf, 0.81931335, ..., 0.5100468 , 0.5100468 ,\n",
       "        0.5100468 ],\n",
       "       ...,\n",
       "       [0.66986462,       -inf, 0.77868293, ..., 0.5355069 , 0.5355069 ,\n",
       "        0.5355069 ],\n",
       "       [0.70183885, 0.68475704,       -inf, ...,       -inf,       -inf,\n",
       "              -inf],\n",
       "       [0.6863458 ,       -inf, 0.81213352, ..., 0.5355069 , 0.5355069 ,\n",
       "        0.5355069 ]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = 0.378267*((res1+res2+res3+res4+res5)/5)+(0.026833*res_area+0.118533*res_edu+0.1481*res_exp+0.209467*res_pos+0.084867*res_salary)+res_willnature\n",
    "res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>1574625077318778880</th>\n",
       "      <th>1573938917198135296</th>\n",
       "      <th>1569987734318219264</th>\n",
       "      <th>1569514123790778368</th>\n",
       "      <th>1562334736783900672</th>\n",
       "      <th>1554782002648055808</th>\n",
       "      <th>1550096565136392192</th>\n",
       "      <th>1541793867911790592</th>\n",
       "      <th>1461666278635864064</th>\n",
       "      <th>...</th>\n",
       "      <th>7539825644220902932</th>\n",
       "      <th>7539825652810837524</th>\n",
       "      <th>7539911436192640532</th>\n",
       "      <th>7539911444782575124</th>\n",
       "      <th>7539911453372509716</th>\n",
       "      <th>7539911466257411604</th>\n",
       "      <th>7539911474847346196</th>\n",
       "      <th>7539911483437280788</th>\n",
       "      <th>7539911492027215380</th>\n",
       "      <th>7539911500617149972</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.7847</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1648527394191052801</td>\n",
       "      <td>0.719971</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.820715</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.662781</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1648527394191052800</td>\n",
       "      <td>0.718688</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.819313</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.662814</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "      <td>0.510047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1648165203084447745</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.791858</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.679729</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.739956</td>\n",
       "      <td>...</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1648165203084447744</td>\n",
       "      <td>0.640477</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.751099</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.650021</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>0.560967</td>\n",
       "      <td>0.560967</td>\n",
       "      <td>0.560967</td>\n",
       "      <td>0.560967</td>\n",
       "      <td>0.560967</td>\n",
       "      <td>0.560967</td>\n",
       "      <td>0.560967</td>\n",
       "      <td>0.560967</td>\n",
       "      <td>0.560967</td>\n",
       "      <td>0.560967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1570</th>\n",
       "      <td>1462698431867912192</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.748668</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1571</th>\n",
       "      <td>1461590578927108096</td>\n",
       "      <td>0.665658</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.784988</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.681224</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1572</th>\n",
       "      <td>1461591923750993920</td>\n",
       "      <td>0.669865</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.778683</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.671495</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1573</th>\n",
       "      <td>1461593160642854912</td>\n",
       "      <td>0.701839</td>\n",
       "      <td>0.684757</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1574</th>\n",
       "      <td>1461595991152132096</td>\n",
       "      <td>0.686346</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.812134</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.699984</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.535507</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1575 rows × 8282 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    jobId  1574625077318778880  1573938917198135296  \\\n",
       "0     1648527394191052802                 -inf                 -inf   \n",
       "1     1648527394191052801             0.719971                 -inf   \n",
       "2     1648527394191052800             0.718688                 -inf   \n",
       "3     1648165203084447745                 -inf                 -inf   \n",
       "4     1648165203084447744             0.640477                 -inf   \n",
       "...                   ...                  ...                  ...   \n",
       "1570  1462698431867912192                 -inf                 -inf   \n",
       "1571  1461590578927108096             0.665658                 -inf   \n",
       "1572  1461591923750993920             0.669865                 -inf   \n",
       "1573  1461593160642854912             0.701839             0.684757   \n",
       "1574  1461595991152132096             0.686346                 -inf   \n",
       "\n",
       "      1569987734318219264  1569514123790778368  1562334736783900672  \\\n",
       "0                    -inf                 -inf                 -inf   \n",
       "1                0.820715                 -inf                 -inf   \n",
       "2                0.819313                 -inf                 -inf   \n",
       "3                0.791858                 -inf                 -inf   \n",
       "4                0.751099                 -inf                 -inf   \n",
       "...                   ...                  ...                  ...   \n",
       "1570                 -inf                 -inf                 -inf   \n",
       "1571             0.784988                 -inf                 -inf   \n",
       "1572             0.778683                 -inf                 -inf   \n",
       "1573                 -inf                 -inf                 -inf   \n",
       "1574             0.812134                 -inf                 -inf   \n",
       "\n",
       "      1554782002648055808  1550096565136392192  1541793867911790592  \\\n",
       "0                    -inf                 -inf               0.7847   \n",
       "1                0.662781                 -inf                 -inf   \n",
       "2                0.662814                 -inf                 -inf   \n",
       "3                0.679729                 -inf                 -inf   \n",
       "4                0.650021                 -inf                 -inf   \n",
       "...                   ...                  ...                  ...   \n",
       "1570                 -inf                 -inf                 -inf   \n",
       "1571             0.681224                 -inf                 -inf   \n",
       "1572             0.671495                 -inf                 -inf   \n",
       "1573                 -inf                 -inf                 -inf   \n",
       "1574             0.699984                 -inf                 -inf   \n",
       "\n",
       "      1461666278635864064  ...  7539825644220902932  7539825652810837524  \\\n",
       "0                    -inf  ...                 -inf                 -inf   \n",
       "1                    -inf  ...             0.510047             0.510047   \n",
       "2                    -inf  ...             0.510047             0.510047   \n",
       "3                0.739956  ...             0.535507             0.535507   \n",
       "4                    -inf  ...             0.560967             0.560967   \n",
       "...                   ...  ...                  ...                  ...   \n",
       "1570             0.748668  ...                 -inf                 -inf   \n",
       "1571                 -inf  ...             0.535507             0.535507   \n",
       "1572                 -inf  ...             0.535507             0.535507   \n",
       "1573                 -inf  ...                 -inf                 -inf   \n",
       "1574                 -inf  ...             0.535507             0.535507   \n",
       "\n",
       "      7539911436192640532  7539911444782575124  7539911453372509716  \\\n",
       "0                    -inf                 -inf                 -inf   \n",
       "1                0.510047             0.510047             0.510047   \n",
       "2                0.510047             0.510047             0.510047   \n",
       "3                0.535507             0.535507             0.535507   \n",
       "4                0.560967             0.560967             0.560967   \n",
       "...                   ...                  ...                  ...   \n",
       "1570                 -inf                 -inf                 -inf   \n",
       "1571             0.535507             0.535507             0.535507   \n",
       "1572             0.535507             0.535507             0.535507   \n",
       "1573                 -inf                 -inf                 -inf   \n",
       "1574             0.535507             0.535507             0.535507   \n",
       "\n",
       "      7539911466257411604  7539911474847346196  7539911483437280788  \\\n",
       "0                    -inf                 -inf                 -inf   \n",
       "1                0.510047             0.510047             0.510047   \n",
       "2                0.510047             0.510047             0.510047   \n",
       "3                0.535507             0.535507             0.535507   \n",
       "4                0.560967             0.560967             0.560967   \n",
       "...                   ...                  ...                  ...   \n",
       "1570                 -inf                 -inf                 -inf   \n",
       "1571             0.535507             0.535507             0.535507   \n",
       "1572             0.535507             0.535507             0.535507   \n",
       "1573                 -inf                 -inf                 -inf   \n",
       "1574             0.535507             0.535507             0.535507   \n",
       "\n",
       "      7539911492027215380  7539911500617149972  \n",
       "0                    -inf                 -inf  \n",
       "1                0.510047             0.510047  \n",
       "2                0.510047             0.510047  \n",
       "3                0.535507             0.535507  \n",
       "4                0.560967             0.560967  \n",
       "...                   ...                  ...  \n",
       "1570                 -inf                 -inf  \n",
       "1571             0.535507             0.535507  \n",
       "1572             0.535507             0.535507  \n",
       "1573                 -inf                 -inf  \n",
       "1574             0.535507             0.535507  \n",
       "\n",
       "[1575 rows x 8282 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(res)\n",
    "df = df.rename(columns = dict(People['resumeId']))\n",
    "df.insert(loc=0, column='jobId', value=Job['jobId'].values)\n",
    "df"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### job2people"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(x):\n",
    "    if isinstance(x,str):\n",
    "        x = x.split(\"| \")\n",
    "        return len(x)\n",
    "    return 0\n",
    "PeopleDetail_['competitionExperienceListCount'] = PeopleDetail_['competitionExperienceList']\n",
    "PeopleDetail_['competitionExperienceListCount'] = PeopleDetail_['competitionExperienceListCount'].map(f)\n",
    "PeopleDetail_;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_p = PeopleDetail_[[\"resumeId\",\"competitionExperienceListCount\"]]\n",
    "count_dic = {0:0,1:0.0339*0.4,2:0.0339*0.4,3:0.0339*0.7,4:0.0339*0.7,5:0.0339*0.7,5:0.0339*1,6:0.0339*1}\n",
    "test_p[\"competitionExperienceListCount\"] = test_p[\"competitionExperienceListCount\"].map(count_dic)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>resumeId</th>\n",
       "      <th>competitionExperienceListCount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1573938917198135296</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1541793867911790592</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1569514123790778368</td>\n",
       "      <td>0.02373</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1550096565136392192</td>\n",
       "      <td>0.01356</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1554782002648055808</td>\n",
       "      <td>0.01356</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8276</th>\n",
       "      <td>7539911466257411604</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8277</th>\n",
       "      <td>7539911474847346196</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8278</th>\n",
       "      <td>7539911500617149972</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8279</th>\n",
       "      <td>7539911483437280788</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8280</th>\n",
       "      <td>7539911492027215380</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8281 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 resumeId  competitionExperienceListCount\n",
       "0     1573938917198135296                         0.00000\n",
       "1     1541793867911790592                         0.00000\n",
       "2     1569514123790778368                         0.02373\n",
       "3     1550096565136392192                         0.01356\n",
       "4     1554782002648055808                         0.01356\n",
       "...                   ...                             ...\n",
       "8276  7539911466257411604                         0.00000\n",
       "8277  7539911474847346196                         0.00000\n",
       "8278  7539911500617149972                         0.00000\n",
       "8279  7539911483437280788                         0.00000\n",
       "8280  7539911492027215380                         0.00000\n",
       "\n",
       "[8281 rows x 2 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>resumeId</th>\n",
       "      <th>data</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1469590908960899072</td>\n",
       "      <td>0.836233</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470745702312312832</td>\n",
       "      <td>0.834449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1490603291757903872</td>\n",
       "      <td>0.818290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1468148406491938816</td>\n",
       "      <td>0.816224</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470307844552261632</td>\n",
       "      <td>0.802496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1466315796216152064</td>\n",
       "      <td>0.581455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1472845935146041344</td>\n",
       "      <td>0.580339</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1470284037246550016</td>\n",
       "      <td>0.535507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1645385086935367680</td>\n",
       "      <td>0.478026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1648345891960127488</td>\n",
       "      <td>0.406044</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       jobId             resumeId      data\n",
       "0        1374177417123467264  1469590908960899072  0.836233\n",
       "1        1374177417123467264  1470745702312312832  0.834449\n",
       "2        1374177417123467264  1490603291757903872  0.818290\n",
       "3        1374177417123467264  1468148406491938816  0.816224\n",
       "4        1374177417123467264  1470307844552261632  0.802496\n",
       "...                      ...                  ...       ...\n",
       "4744800  1648527394191052802  1466315796216152064  0.581455\n",
       "4744801  1648527394191052802  1472845935146041344  0.580339\n",
       "4744802  1648527394191052802  1470284037246550016  0.535507\n",
       "4744803  1648527394191052802  1645385086935367680  0.478026\n",
       "4744804  1648527394191052802  1648345891960127488  0.406044\n",
       "\n",
       "[4744805 rows x 3 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jobpeople = pd.melt(df, id_vars='jobId', value_vars=df.columns[1:], var_name='resumeId', value_name='data')\n",
    "jobpeople = jobpeople[~np.isinf(jobpeople['data'])]  # 去除 inf 数据\n",
    "# 按'jobId'升序和'data'降序排序\n",
    "jobpeople = jobpeople.sort_values(by=['jobId', 'data'], ascending=[True, False])\n",
    "\n",
    "# 重置索引\n",
    "jobpeople = jobpeople.reset_index(drop=True)\n",
    "jobpeople"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_dic = dict(zip(test_p['resumeId'].values.tolist(),test_p['competitionExperienceListCount'].values.tolist()))\n",
    "add_dic;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(row):\n",
    "    row[\"data\"] += add_dic[row['resumeId']]\n",
    "    return row    \n",
    "# melted_df.apply(lambda row:f(row),axis=1);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 计算每个 jobId 对应的行数\n",
    "# counts = melted_df.groupby('jobId')['resumeId'].count()\n",
    "\n",
    "# # 找到所有行数大于 2000 的 jobId\n",
    "# large_jobs = counts[counts > 6000].index\n",
    "# # 筛选掉这些 jobId 中 data 值小于 0.4 的行\n",
    "# melted_df = melted_df[~((melted_df['jobId'].isin(large_jobs)) & (melted_df['data'] <= 0.51))]\n",
    "# melted_df = melted_df.reset_index(drop=True)\n",
    "# melted_df"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### people2job"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "res1 = np.load(\"res1.npz\")['arr_0'].T\n",
    "res2 = np.load(\"res2.npz\")['arr_0'].T\n",
    "res3 = np.load(\"res3.npz\")['arr_0'].T\n",
    "res4 = np.load(\"res4.npz\")['arr_0'].T\n",
    "res5 = np.load(\"short.npz\")['arr_0'].T\n",
    "res_area = np.load(\"res_area.npz\")['arr_0'].T\n",
    "res_edu = np.load(\"res_edu.npz\")['arr_0'].T\n",
    "res_exp = np.load(\"res_exp.npz\")[\"arr_0\"].T\n",
    "res_pos = np.load(\"res_pos.npz\")['arr_0'].T\n",
    "res_salary = np.load(\"res_salary.npz\")['arr_0'].T\n",
    "res_willnature = np.load(\"res_willnature.npz\")['arr_0'].T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8281, 1575)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_willnature[res_willnature==1] = 0\n",
    "res_willnature.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[      -inf, 0.75939485, 0.75864811, ..., 0.67642463, 0.71315005,\n",
       "        0.69507491],\n",
       "       [      -inf,       -inf,       -inf, ...,       -inf, 0.69415019,\n",
       "              -inf],\n",
       "       [      -inf, 0.80897476, 0.80815878, ..., 0.73976139,       -inf,\n",
       "        0.7773461 ],\n",
       "       ...,\n",
       "       [      -inf, 0.5477128 , 0.5477128 , ..., 0.5982229 ,       -inf,\n",
       "        0.5982229 ],\n",
       "       [      -inf, 0.5477128 , 0.5477128 , ..., 0.5982229 ,       -inf,\n",
       "        0.5982229 ],\n",
       "       [      -inf, 0.5477128 , 0.5477128 , ..., 0.5982229 ,       -inf,\n",
       "        0.5982229 ]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res2 = 0.220167*((res1+res2+res3+res4+res5)/5)+(0.033733*res_area+0.1988*res_edu+0.098833*res_exp+0.182733*res_pos+0.168367*res_salary)+res_willnature\n",
    "res2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>resumeId</th>\n",
       "      <th>1648527394191052802</th>\n",
       "      <th>1648527394191052801</th>\n",
       "      <th>1648527394191052800</th>\n",
       "      <th>1648165203084447745</th>\n",
       "      <th>1648165203084447744</th>\n",
       "      <th>1648165203080253441</th>\n",
       "      <th>1648165203080253440</th>\n",
       "      <th>1631112859985510400</th>\n",
       "      <th>1631112859897430016</th>\n",
       "      <th>...</th>\n",
       "      <th>1472840476490072064</th>\n",
       "      <th>1466286732872908800</th>\n",
       "      <th>1466287880098938880</th>\n",
       "      <th>1465938789343035392</th>\n",
       "      <th>1462695954653249536</th>\n",
       "      <th>1462698431867912192</th>\n",
       "      <th>1461590578927108096</th>\n",
       "      <th>1461591923750993920</th>\n",
       "      <th>1461593160642854912</th>\n",
       "      <th>1461595991152132096</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1574625077318778880</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.759395</td>\n",
       "      <td>0.758648</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.623629</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.580614</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.753896</td>\n",
       "      <td>0.735756</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.673976</td>\n",
       "      <td>0.676425</td>\n",
       "      <td>0.71315</td>\n",
       "      <td>0.695075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1573938917198135296</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.729675</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.69415</td>\n",
       "      <td>-inf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1569987734318219264</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.808975</td>\n",
       "      <td>0.808159</td>\n",
       "      <td>0.747430</td>\n",
       "      <td>0.688015</td>\n",
       "      <td>0.745136</td>\n",
       "      <td>0.641766</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.820809</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.743431</td>\n",
       "      <td>0.739761</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.777346</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1569514123790778368</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1562334736783900672</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8276</th>\n",
       "      <td>7539911466257411604</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.648733</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.608973</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.598223</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8277</th>\n",
       "      <td>7539911474847346196</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.648733</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.608973</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.598223</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8278</th>\n",
       "      <td>7539911483437280788</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.648733</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.608973</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.598223</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8279</th>\n",
       "      <td>7539911492027215380</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.648733</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.608973</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.598223</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8280</th>\n",
       "      <td>7539911500617149972</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.648733</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.608973</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>...</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.547713</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>-inf</td>\n",
       "      <td>0.598223</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8281 rows × 1576 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 resumeId  1648527394191052802  1648527394191052801  \\\n",
       "0     1574625077318778880                 -inf             0.759395   \n",
       "1     1573938917198135296                 -inf                 -inf   \n",
       "2     1569987734318219264                 -inf             0.808975   \n",
       "3     1569514123790778368                 -inf                 -inf   \n",
       "4     1562334736783900672                 -inf                 -inf   \n",
       "...                   ...                  ...                  ...   \n",
       "8276  7539911466257411604                 -inf             0.547713   \n",
       "8277  7539911474847346196                 -inf             0.547713   \n",
       "8278  7539911483437280788                 -inf             0.547713   \n",
       "8279  7539911492027215380                 -inf             0.547713   \n",
       "8280  7539911500617149972                 -inf             0.547713   \n",
       "\n",
       "      1648527394191052800  1648165203084447745  1648165203084447744  \\\n",
       "0                0.758648                 -inf             0.623629   \n",
       "1                    -inf                 -inf                 -inf   \n",
       "2                0.808159             0.747430             0.688015   \n",
       "3                    -inf                 -inf                 -inf   \n",
       "4                    -inf                 -inf                 -inf   \n",
       "...                   ...                  ...                  ...   \n",
       "8276             0.547713             0.598223             0.648733   \n",
       "8277             0.547713             0.598223             0.648733   \n",
       "8278             0.547713             0.598223             0.648733   \n",
       "8279             0.547713             0.598223             0.648733   \n",
       "8280             0.547713             0.598223             0.648733   \n",
       "\n",
       "      1648165203080253441  1648165203080253440  1631112859985510400  \\\n",
       "0                    -inf             0.580614                 -inf   \n",
       "1                    -inf                 -inf                 -inf   \n",
       "2                0.745136             0.641766                 -inf   \n",
       "3                    -inf                 -inf                 -inf   \n",
       "4                    -inf                 -inf                 -inf   \n",
       "...                   ...                  ...                  ...   \n",
       "8276             0.598223             0.608973                 -inf   \n",
       "8277             0.598223             0.608973                 -inf   \n",
       "8278             0.598223             0.608973                 -inf   \n",
       "8279             0.598223             0.608973                 -inf   \n",
       "8280             0.598223             0.608973                 -inf   \n",
       "\n",
       "      1631112859897430016  ...  1472840476490072064  1466286732872908800  \\\n",
       "0                    -inf  ...                 -inf                 -inf   \n",
       "1                    -inf  ...                 -inf                 -inf   \n",
       "2                    -inf  ...                 -inf                 -inf   \n",
       "3                    -inf  ...                 -inf                 -inf   \n",
       "4                    -inf  ...                 -inf                 -inf   \n",
       "...                   ...  ...                  ...                  ...   \n",
       "8276                 -inf  ...                 -inf                 -inf   \n",
       "8277                 -inf  ...                 -inf                 -inf   \n",
       "8278                 -inf  ...                 -inf                 -inf   \n",
       "8279                 -inf  ...                 -inf                 -inf   \n",
       "8280                 -inf  ...                 -inf                 -inf   \n",
       "\n",
       "      1466287880098938880  1465938789343035392  1462695954653249536  \\\n",
       "0                    -inf             0.753896             0.735756   \n",
       "1                    -inf             0.729675                 -inf   \n",
       "2                    -inf                 -inf             0.820809   \n",
       "3                    -inf                 -inf                 -inf   \n",
       "4                    -inf                 -inf                 -inf   \n",
       "...                   ...                  ...                  ...   \n",
       "8276                 -inf                 -inf             0.547713   \n",
       "8277                 -inf                 -inf             0.547713   \n",
       "8278                 -inf                 -inf             0.547713   \n",
       "8279                 -inf                 -inf             0.547713   \n",
       "8280                 -inf                 -inf             0.547713   \n",
       "\n",
       "      1462698431867912192  1461590578927108096  1461591923750993920  \\\n",
       "0                    -inf             0.673976             0.676425   \n",
       "1                    -inf                 -inf                 -inf   \n",
       "2                    -inf             0.743431             0.739761   \n",
       "3                    -inf                 -inf                 -inf   \n",
       "4                    -inf                 -inf                 -inf   \n",
       "...                   ...                  ...                  ...   \n",
       "8276                 -inf             0.598223             0.598223   \n",
       "8277                 -inf             0.598223             0.598223   \n",
       "8278                 -inf             0.598223             0.598223   \n",
       "8279                 -inf             0.598223             0.598223   \n",
       "8280                 -inf             0.598223             0.598223   \n",
       "\n",
       "      1461593160642854912  1461595991152132096  \n",
       "0                 0.71315             0.695075  \n",
       "1                 0.69415                 -inf  \n",
       "2                    -inf             0.777346  \n",
       "3                    -inf                 -inf  \n",
       "4                    -inf                 -inf  \n",
       "...                   ...                  ...  \n",
       "8276                 -inf             0.598223  \n",
       "8277                 -inf             0.598223  \n",
       "8278                 -inf             0.598223  \n",
       "8279                 -inf             0.598223  \n",
       "8280                 -inf             0.598223  \n",
       "\n",
       "[8281 rows x 1576 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(res2)\n",
    "df = df.rename(columns = dict(Job['jobId']))\n",
    "df.insert(loc=0, column='resumeId', value=People['resumeId'].values)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>resumeId</th>\n",
       "      <th>jobId</th>\n",
       "      <th>data2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1461512488951611392</td>\n",
       "      <td>1507240831520735232</td>\n",
       "      <td>0.652816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1461512488951611392</td>\n",
       "      <td>1482191940312236045</td>\n",
       "      <td>0.652816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1461512488951611392</td>\n",
       "      <td>1482185263353561092</td>\n",
       "      <td>0.631956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1461512488951611392</td>\n",
       "      <td>1482192055261331461</td>\n",
       "      <td>0.631956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1461512488951611392</td>\n",
       "      <td>1531529924001792000</td>\n",
       "      <td>0.623166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>7539911552156757524</td>\n",
       "      <td>1482185135670558722</td>\n",
       "      <td>0.497203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>7539911552156757524</td>\n",
       "      <td>1482185135670558721</td>\n",
       "      <td>0.497203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>7539911552156757524</td>\n",
       "      <td>1482184690793316354</td>\n",
       "      <td>0.497203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>7539911552156757524</td>\n",
       "      <td>1541254101239726081</td>\n",
       "      <td>0.478943</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>7539911552156757524</td>\n",
       "      <td>1482185135670558725</td>\n",
       "      <td>0.457443</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    resumeId                jobId     data2\n",
       "0        1461512488951611392  1507240831520735232  0.652816\n",
       "1        1461512488951611392  1482191940312236045  0.652816\n",
       "2        1461512488951611392  1482185263353561092  0.631956\n",
       "3        1461512488951611392  1482192055261331461  0.631956\n",
       "4        1461512488951611392  1531529924001792000  0.623166\n",
       "...                      ...                  ...       ...\n",
       "4744800  7539911552156757524  1482185135670558722  0.497203\n",
       "4744801  7539911552156757524  1482185135670558721  0.497203\n",
       "4744802  7539911552156757524  1482184690793316354  0.497203\n",
       "4744803  7539911552156757524  1541254101239726081  0.478943\n",
       "4744804  7539911552156757524  1482185135670558725  0.457443\n",
       "\n",
       "[4744805 rows x 3 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "melted_df = pd.melt(df, id_vars='resumeId', value_vars=df.columns[1:], var_name='jobId', value_name='data2')\n",
    "melted_df = melted_df[~np.isinf(melted_df['data2'])]  # 去除 inf 数据\n",
    "# 按'jobId'升序和'data'降序排序\n",
    "melted_df = melted_df.sort_values(by=['resumeId', 'data2'], ascending=[True, False])\n",
    "\n",
    "# 重置索引\n",
    "melted_df = melted_df.reset_index(drop=True)\n",
    "melted_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>resumeId</th>\n",
       "      <th>jobId</th>\n",
       "      <th>data2</th>\n",
       "      <th>company</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1461512488951611392</td>\n",
       "      <td>1507240831520735232</td>\n",
       "      <td>0.652816</td>\n",
       "      <td>龙湖集团</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1461512488951611392</td>\n",
       "      <td>1482191940312236045</td>\n",
       "      <td>0.652816</td>\n",
       "      <td>嫚熙控股(广州)有限公司</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1461512488951611392</td>\n",
       "      <td>1482185263353561092</td>\n",
       "      <td>0.631956</td>\n",
       "      <td>数字广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1461512488951611392</td>\n",
       "      <td>1482192055261331461</td>\n",
       "      <td>0.631956</td>\n",
       "      <td>蓝月亮</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1461512488951611392</td>\n",
       "      <td>1531529924001792000</td>\n",
       "      <td>0.623166</td>\n",
       "      <td>快塑电商</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>7539911552156757524</td>\n",
       "      <td>1482185135670558722</td>\n",
       "      <td>0.497203</td>\n",
       "      <td>网易集团</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>7539911552156757524</td>\n",
       "      <td>1482185135670558721</td>\n",
       "      <td>0.497203</td>\n",
       "      <td>网易集团</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>7539911552156757524</td>\n",
       "      <td>1482184690793316354</td>\n",
       "      <td>0.497203</td>\n",
       "      <td>有米科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>7539911552156757524</td>\n",
       "      <td>1541254101239726081</td>\n",
       "      <td>0.478943</td>\n",
       "      <td>活树信息</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>7539911552156757524</td>\n",
       "      <td>1482185135670558725</td>\n",
       "      <td>0.457443</td>\n",
       "      <td>腾讯音乐娱乐集团</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    resumeId                jobId     data2       company\n",
       "0        1461512488951611392  1507240831520735232  0.652816          龙湖集团\n",
       "1        1461512488951611392  1482191940312236045  0.652816  嫚熙控股(广州)有限公司\n",
       "2        1461512488951611392  1482185263353561092  0.631956          数字广东\n",
       "3        1461512488951611392  1482192055261331461  0.631956           蓝月亮\n",
       "4        1461512488951611392  1531529924001792000  0.623166          快塑电商\n",
       "...                      ...                  ...       ...           ...\n",
       "4744800  7539911552156757524  1482185135670558722  0.497203          网易集团\n",
       "4744801  7539911552156757524  1482185135670558721  0.497203          网易集团\n",
       "4744802  7539911552156757524  1482184690793316354  0.497203          有米科技\n",
       "4744803  7539911552156757524  1541254101239726081  0.478943          活树信息\n",
       "4744804  7539911552156757524  1482185135670558725  0.457443      腾讯音乐娱乐集团\n",
       "\n",
       "[4744805 rows x 4 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "people_job = melted_df\n",
    "people_job['company'] = people_job['jobId']\n",
    "name_dic = dict(zip(Job.jobId.values.tolist(),Job.shortName.values.tolist()))\n",
    "people_job['company'] = people_job['company'].map(name_dic)\n",
    "people_job"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Match"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "people_job;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "jobpeople;\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>resumeId</th>\n",
       "      <th>data</th>\n",
       "      <th>data2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1469590908960899072</td>\n",
       "      <td>0.836233</td>\n",
       "      <td>0.827064</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470745702312312832</td>\n",
       "      <td>0.834449</td>\n",
       "      <td>0.826026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1490603291757903872</td>\n",
       "      <td>0.818290</td>\n",
       "      <td>0.816621</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1468148406491938816</td>\n",
       "      <td>0.816224</td>\n",
       "      <td>0.815418</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470307844552261632</td>\n",
       "      <td>0.802496</td>\n",
       "      <td>0.807428</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1466315796216152064</td>\n",
       "      <td>0.581455</td>\n",
       "      <td>0.598333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1472845935146041344</td>\n",
       "      <td>0.580339</td>\n",
       "      <td>0.597683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1470284037246550016</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.598223</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1645385086935367680</td>\n",
       "      <td>0.478026</td>\n",
       "      <td>0.589088</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1648345891960127488</td>\n",
       "      <td>0.406044</td>\n",
       "      <td>0.475809</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       jobId             resumeId      data     data2\n",
       "0        1374177417123467264  1469590908960899072  0.836233  0.827064\n",
       "1        1374177417123467264  1470745702312312832  0.834449  0.826026\n",
       "2        1374177417123467264  1490603291757903872  0.818290  0.816621\n",
       "3        1374177417123467264  1468148406491938816  0.816224  0.815418\n",
       "4        1374177417123467264  1470307844552261632  0.802496  0.807428\n",
       "...                      ...                  ...       ...       ...\n",
       "4744800  1648527394191052802  1466315796216152064  0.581455  0.598333\n",
       "4744801  1648527394191052802  1472845935146041344  0.580339  0.597683\n",
       "4744802  1648527394191052802  1470284037246550016  0.535507  0.598223\n",
       "4744803  1648527394191052802  1645385086935367680  0.478026  0.589088\n",
       "4744804  1648527394191052802  1648345891960127488  0.406044  0.475809\n",
       "\n",
       "[4744805 rows x 4 columns]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merged_data = pd.merge(jobpeople,people_job, on=['resumeId', 'jobId'])\n",
    "merged_data = merged_data[['jobId','resumeId','data','data2']]\n",
    "merged_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>resumeId</th>\n",
       "      <th>data</th>\n",
       "      <th>data2</th>\n",
       "      <th>count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1469590908960899072</td>\n",
       "      <td>0.836233</td>\n",
       "      <td>0.827064</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470745702312312832</td>\n",
       "      <td>0.834449</td>\n",
       "      <td>0.826026</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1490603291757903872</td>\n",
       "      <td>0.818290</td>\n",
       "      <td>0.816621</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1468148406491938816</td>\n",
       "      <td>0.816224</td>\n",
       "      <td>0.815418</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470307844552261632</td>\n",
       "      <td>0.802496</td>\n",
       "      <td>0.807428</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1466315796216152064</td>\n",
       "      <td>0.581455</td>\n",
       "      <td>0.598333</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1472845935146041344</td>\n",
       "      <td>0.580339</td>\n",
       "      <td>0.597683</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1470284037246550016</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1645385086935367680</td>\n",
       "      <td>0.478026</td>\n",
       "      <td>0.589088</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1648345891960127488</td>\n",
       "      <td>0.406044</td>\n",
       "      <td>0.475809</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       jobId             resumeId      data     data2  count\n",
       "0        1374177417123467264  1469590908960899072  0.836233  0.827064      1\n",
       "1        1374177417123467264  1470745702312312832  0.834449  0.826026      1\n",
       "2        1374177417123467264  1490603291757903872  0.818290  0.816621      1\n",
       "3        1374177417123467264  1468148406491938816  0.816224  0.815418      1\n",
       "4        1374177417123467264  1470307844552261632  0.802496  0.807428      1\n",
       "...                      ...                  ...       ...       ...    ...\n",
       "4744800  1648527394191052802  1466315796216152064  0.581455  0.598333      6\n",
       "4744801  1648527394191052802  1472845935146041344  0.580339  0.597683      6\n",
       "4744802  1648527394191052802  1470284037246550016  0.535507  0.598223      6\n",
       "4744803  1648527394191052802  1645385086935367680  0.478026  0.589088      6\n",
       "4744804  1648527394191052802  1648345891960127488  0.406044  0.475809      6\n",
       "\n",
       "[4744805 rows x 5 columns]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp = Job[['jobId','count']]\n",
    "temp['count'] = temp['count'].map(lambda x:-1 if x==0 else x)\n",
    "dic = dict(zip(temp['jobId'].values.tolist(),temp['count'].values.tolist()))\n",
    "merged_data['count'] = merged_data['jobId']\n",
    "merged_data['count'] = merged_data['count'].map(dic)\n",
    "merged_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test = pd.DataFrame()\n",
    "test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    4744685\n",
      "2        120\n",
      "Name: round_1, dtype: int64\n",
      "0    4744577\n",
      "2        108\n",
      "Name: round_2, dtype: int64\n",
      "0    4744466\n",
      "2        111\n",
      "Name: round_3, dtype: int64\n",
      "0    4744361\n",
      "2        105\n",
      "Name: round_4, dtype: int64\n",
      "0    4744261\n",
      "2        100\n",
      "Name: round_5, dtype: int64\n",
      "0    4744160\n",
      "2        101\n",
      "Name: round_6, dtype: int64\n",
      "0    4744060\n",
      "2        100\n",
      "Name: round_7, dtype: int64\n",
      "0    4743962\n",
      "2         98\n",
      "Name: round_8, dtype: int64\n",
      "0    4743864\n",
      "2         98\n",
      "Name: round_9, dtype: int64\n",
      "0    4743769\n",
      "2         95\n",
      "Name: round_10, dtype: int64\n",
      "0    4743677\n",
      "2         92\n",
      "Name: round_11, dtype: int64\n",
      "0    4743596\n",
      "2         81\n",
      "Name: round_12, dtype: int64\n",
      "0    4743513\n",
      "2         83\n",
      "Name: round_13, dtype: int64\n",
      "0    4743427\n",
      "2         86\n",
      "Name: round_14, dtype: int64\n",
      "0    4743340\n",
      "2         87\n",
      "Name: round_15, dtype: int64\n",
      "0    4743258\n",
      "2         82\n",
      "Name: round_16, dtype: int64\n",
      "0    4743182\n",
      "2         76\n",
      "Name: round_17, dtype: int64\n",
      "0    4743104\n",
      "2         78\n",
      "Name: round_18, dtype: int64\n",
      "0    4743025\n",
      "2         79\n",
      "Name: round_19, dtype: int64\n",
      "0    4742952\n",
      "2         73\n",
      "Name: round_20, dtype: int64\n",
      "0    4742877\n",
      "2         75\n",
      "Name: round_21, dtype: int64\n",
      "0    4742806\n",
      "2         71\n",
      "Name: round_22, dtype: int64\n",
      "0    4742738\n",
      "2         68\n",
      "Name: round_23, dtype: int64\n",
      "0    4742664\n",
      "2         74\n",
      "Name: round_24, dtype: int64\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_9028/3204567035.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     54\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     55\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 56\u001b[1;33m     \u001b[0mmerged_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mset_round_for_group2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmerged_data\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     57\u001b[0m     \u001b[0mmerged_data\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mnew_columns\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmerged_data\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mnew_columns\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m0\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m==\u001b[0m\u001b[1;36m1\u001b[0m \u001b[1;32melse\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     58\u001b[0m     \u001b[0mtest\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtest\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmerged_data\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mmerged_data\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mnew_columns\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m==\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_9028/3204567035.py\u001b[0m in \u001b[0;36mset_round_for_group2\u001b[1;34m(df)\u001b[0m\n\u001b[0;32m     45\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mgroup\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     46\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 47\u001b[1;33m         \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgroupby\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"jobId\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mset_round_for_group_\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     48\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     49\u001b[0m         \u001b[0mindex\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mres\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\pandas\\core\\groupby\\groupby.py\u001b[0m in \u001b[0;36mapply\u001b[1;34m(self, func, *args, **kwargs)\u001b[0m\n\u001b[0;32m   1565\u001b[0m                     \u001b[0mold_msg\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mFutureWarning\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnew_msg\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1566\u001b[0m                 ) if is_np_func else nullcontext():\n\u001b[1;32m-> 1567\u001b[1;33m                     \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_python_apply_general\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_selected_obj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1568\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1569\u001b[0m                 \u001b[1;31m# gh-20949\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\pandas\\core\\groupby\\groupby.py\u001b[0m in \u001b[0;36m_python_apply_general\u001b[1;34m(self, f, data, not_indexed_same, is_transform, is_agg)\u001b[0m\n\u001b[0;32m   1627\u001b[0m             \u001b[0mdata\u001b[0m \u001b[0mafter\u001b[0m \u001b[0mapplying\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1628\u001b[0m         \"\"\"\n\u001b[1;32m-> 1629\u001b[1;33m         \u001b[0mvalues\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmutated\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgrouper\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1630\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mnot_indexed_same\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1631\u001b[0m             \u001b[0mnot_indexed_same\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmutated\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmutated\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\pandas\\core\\groupby\\ops.py\u001b[0m in \u001b[0;36mapply\u001b[1;34m(self, f, data, axis)\u001b[0m\n\u001b[0;32m    837\u001b[0m             \u001b[1;31m# group might be modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    838\u001b[0m             \u001b[0mgroup_axes\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgroup\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maxes\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 839\u001b[1;33m             \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgroup\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    840\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mmutated\u001b[0m \u001b[1;32mand\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0m_is_indexed_like\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mres\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mgroup_axes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    841\u001b[0m                 \u001b[0mmutated\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_9028/3204567035.py\u001b[0m in \u001b[0;36mset_round_for_group_\u001b[1;34m(group)\u001b[0m\n\u001b[0;32m     16\u001b[0m             \u001b[1;31m# print(count)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     17\u001b[0m             \u001b[1;31m# print(\"满足要求的人\")\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 18\u001b[1;33m             \u001b[0mgroup\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgroup\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mf\"{new_columns} != 0\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     19\u001b[0m             \u001b[0mquery_str\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     20\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mn\u001b[0m\u001b[1;33m>\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\pandas\\util\\_decorators.py\u001b[0m in \u001b[0;36mwrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    329\u001b[0m                     \u001b[0mstacklevel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfind_stack_level\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    330\u001b[0m                 )\n\u001b[1;32m--> 331\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    332\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    333\u001b[0m         \u001b[1;31m# error: \"Callable[[VarArg(Any), KwArg(Any)], Any]\" has no\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36mquery\u001b[1;34m(self, expr, inplace, **kwargs)\u001b[0m\n\u001b[0;32m   4472\u001b[0m         \u001b[0mkwargs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"level\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"level\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4473\u001b[0m         \u001b[0mkwargs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"target\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4474\u001b[1;33m         \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0meval\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mexpr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4475\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4476\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\pandas\\util\\_decorators.py\u001b[0m in \u001b[0;36mwrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    329\u001b[0m                     \u001b[0mstacklevel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfind_stack_level\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    330\u001b[0m                 )\n\u001b[1;32m--> 331\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    332\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    333\u001b[0m         \u001b[1;31m# error: \"Callable[[VarArg(Any), KwArg(Any)], Any]\" has no\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36meval\u001b[1;34m(self, expr, inplace, **kwargs)\u001b[0m\n\u001b[0;32m   4603\u001b[0m         \u001b[0minplace\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvalidate_bool_kwarg\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minplace\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"inplace\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4604\u001b[0m         \u001b[0mkwargs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"level\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"level\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4605\u001b[1;33m         \u001b[0mindex_resolvers\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_index_resolvers\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4606\u001b[0m         \u001b[0mcolumn_resolvers\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_cleaned_column_resolvers\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4607\u001b[0m         \u001b[0mresolvers\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcolumn_resolvers\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex_resolvers\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m_get_index_resolvers\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    616\u001b[0m         \u001b[0md\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mdict\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mSeries\u001b[0m \u001b[1;33m|\u001b[0m \u001b[0mMultiIndex\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    617\u001b[0m         \u001b[1;32mfor\u001b[0m \u001b[0maxis_name\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_AXIS_ORDERS\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 618\u001b[1;33m             \u001b[0md\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_axis_resolvers\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maxis_name\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    619\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    620\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[1;33m{\u001b[0m\u001b[0mclean_column_name\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mv\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mk\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mv\u001b[0m \u001b[1;32min\u001b[0m \u001b[0md\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m_get_axis_resolvers\u001b[1;34m(self, axis)\u001b[0m\n\u001b[0;32m    597\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    598\u001b[0m             \u001b[0mlevel_values\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0maxis_index\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_level_values\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlevel\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 599\u001b[1;33m             \u001b[0ms\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlevel_values\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_series\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    600\u001b[0m             \u001b[0ms\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0maxis_index\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    601\u001b[0m             \u001b[0md\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mto_series\u001b[1;34m(self, index, name)\u001b[0m\n\u001b[0;32m   1655\u001b[0m             \u001b[0mname\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1656\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1657\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mSeries\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_values\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcopy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1658\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1659\u001b[0m     def to_frame(\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "n = 1\n",
    "while n<80:\n",
    "    new_columns = f\"round_{n}\"\n",
    "    merged_data[new_columns] = 0\n",
    "    remaining_job_slots = merged_data.groupby(\"jobId\")[\"count\"].first()\n",
    "    df_filtered = merged_data[merged_data[\"jobId\"].map(remaining_job_slots) != 0]\n",
    "    \n",
    "    merged_data.loc[df_filtered.groupby(\"resumeId\")[\"data2\"].idxmax(),new_columns] = 1\n",
    "    merged_data\n",
    "    \n",
    "    def set_round_for_group2(df):\n",
    "        counts = df.groupby(\"jobId\")['count'].max().to_dict()\n",
    "        def set_round_for_group_(group):\n",
    "            count = counts[group[\"jobId\"].iloc[0]]\n",
    "            # print(\"--------------------\")\n",
    "            # print(count)\n",
    "            # print(\"满足要求的人\")\n",
    "            group = group.query(f\"{new_columns} != 0\")\n",
    "            query_str = \"\"\n",
    "            if n>1:  \n",
    "                for i in range(1,n):\n",
    "                    query_str += f\"(round_{i} !=2) & \"\n",
    "                query_str = query_str[:-3]\n",
    "                # print(query_str)\n",
    "                group = group.query(query_str)\n",
    "            # print(group)\n",
    "            # print(\"--------------------\")\n",
    "            # print(\"\\n\")\n",
    "            if count <0 :\n",
    "                if len(group) !=0:\n",
    "                    group.loc[group['jobId'].index[0]:group['jobId'].index[0]+1, new_columns] = 2\n",
    "                    group['count'] -=1\n",
    "                else:\n",
    "                    pass\n",
    "            else:\n",
    "                if len(group) !=0:\n",
    "                    if len(group) >= count:\n",
    "                        group.loc[group['jobId'].index[0]:group['jobId'].index[0]+count-1, new_columns] = 2\n",
    "                        group['count'] -= count\n",
    "                    else:\n",
    "                        group[new_columns] = 2\n",
    "                        group[\"count\"] -= len(group)\n",
    "                else:\n",
    "                    pass\n",
    "            return group\n",
    "        \n",
    "        res = df.groupby(\"jobId\").apply(set_round_for_group_)\n",
    "        \n",
    "        index = [i[1] for i in res.index]\n",
    "        df.loc[index,new_columns] = res[new_columns].values             # 将结果返回到原来的矩阵上\n",
    "        \n",
    "        dic_ = dict(zip(res['jobId'].values.tolist(),res['count'].values.tolist()))\n",
    "        df.loc[df['jobId'].isin(dic_.keys()), 'count'] = df['jobId'].map(dic_)\n",
    "        return df\n",
    "\n",
    "    merged_data = set_round_for_group2(merged_data)\n",
    "    merged_data[new_columns] = merged_data[new_columns].map(lambda x:0 if x==1 else x)\n",
    "    test = test.append(merged_data[merged_data[new_columns]==2])\n",
    "    # print(test)\n",
    "    print(merged_data[new_columns].value_counts())\n",
    "    merged_data = merged_data[merged_data[new_columns] !=2 ]\n",
    "    # if merged_data[new_columns].value_counts()[2]==0:\n",
    "    #     break\n",
    "    n+=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1613439889204969472    4\n",
       "1514089434499383296    4\n",
       "1461589362696388608    3\n",
       "1473843718837633024    3\n",
       "1482185488751263744    3\n",
       "                      ..\n",
       "1482194190791213060    1\n",
       "1482193772577161217    1\n",
       "1482192783145041923    1\n",
       "1482192311990484995    1\n",
       "1648527394191052801    1\n",
       "Name: jobId, Length: 110, dtype: int64"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# filtered['jobId'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>resumeId</th>\n",
       "      <th>data</th>\n",
       "      <th>data2</th>\n",
       "      <th>count</th>\n",
       "      <th>round_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1469590908960899072</td>\n",
       "      <td>0.836233</td>\n",
       "      <td>0.827064</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470745702312312832</td>\n",
       "      <td>0.834449</td>\n",
       "      <td>0.826026</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1490603291757903872</td>\n",
       "      <td>0.818290</td>\n",
       "      <td>0.816621</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1468148406491938816</td>\n",
       "      <td>0.816224</td>\n",
       "      <td>0.815418</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470307844552261632</td>\n",
       "      <td>0.802496</td>\n",
       "      <td>0.807428</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1466315796216152064</td>\n",
       "      <td>0.581455</td>\n",
       "      <td>0.598333</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1472845935146041344</td>\n",
       "      <td>0.580339</td>\n",
       "      <td>0.597683</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1470284037246550016</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1645385086935367680</td>\n",
       "      <td>0.478026</td>\n",
       "      <td>0.589088</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1648345891960127488</td>\n",
       "      <td>0.406044</td>\n",
       "      <td>0.475809</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       jobId             resumeId      data     data2  count  \\\n",
       "0        1374177417123467264  1469590908960899072  0.836233  0.827064      1   \n",
       "1        1374177417123467264  1470745702312312832  0.834449  0.826026      1   \n",
       "2        1374177417123467264  1490603291757903872  0.818290  0.816621      1   \n",
       "3        1374177417123467264  1468148406491938816  0.816224  0.815418      1   \n",
       "4        1374177417123467264  1470307844552261632  0.802496  0.807428      1   \n",
       "...                      ...                  ...       ...       ...    ...   \n",
       "4744800  1648527394191052802  1466315796216152064  0.581455  0.598333      6   \n",
       "4744801  1648527394191052802  1472845935146041344  0.580339  0.597683      6   \n",
       "4744802  1648527394191052802  1470284037246550016  0.535507  0.598223      6   \n",
       "4744803  1648527394191052802  1645385086935367680  0.478026  0.589088      6   \n",
       "4744804  1648527394191052802  1648345891960127488  0.406044  0.475809      6   \n",
       "\n",
       "         round_1  \n",
       "0              0  \n",
       "1              0  \n",
       "2              0  \n",
       "3              0  \n",
       "4              0  \n",
       "...          ...  \n",
       "4744800        0  \n",
       "4744801        0  \n",
       "4744802        0  \n",
       "4744803        0  \n",
       "4744804        0  \n",
       "\n",
       "[4744805 rows x 6 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merged_data['round_1'] = 0\n",
    "remaining_job_slots = merged_data.groupby(\"jobId\")[\"count\"].first()\n",
    "df_filtered = merged_data[merged_data[\"jobId\"].map(remaining_job_slots) != 0]\n",
    "df_filtered"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>resumeId</th>\n",
       "      <th>data</th>\n",
       "      <th>data2</th>\n",
       "      <th>count</th>\n",
       "      <th>round_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1469590908960899072</td>\n",
       "      <td>0.836233</td>\n",
       "      <td>0.827064</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470745702312312832</td>\n",
       "      <td>0.834449</td>\n",
       "      <td>0.826026</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1490603291757903872</td>\n",
       "      <td>0.818290</td>\n",
       "      <td>0.816621</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1468148406491938816</td>\n",
       "      <td>0.816224</td>\n",
       "      <td>0.815418</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470307844552261632</td>\n",
       "      <td>0.802496</td>\n",
       "      <td>0.807428</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1466315796216152064</td>\n",
       "      <td>0.581455</td>\n",
       "      <td>0.598333</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1472845935146041344</td>\n",
       "      <td>0.580339</td>\n",
       "      <td>0.597683</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1470284037246550016</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1645385086935367680</td>\n",
       "      <td>0.478026</td>\n",
       "      <td>0.589088</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1648345891960127488</td>\n",
       "      <td>0.406044</td>\n",
       "      <td>0.475809</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       jobId             resumeId      data     data2  count  \\\n",
       "0        1374177417123467264  1469590908960899072  0.836233  0.827064      1   \n",
       "1        1374177417123467264  1470745702312312832  0.834449  0.826026      1   \n",
       "2        1374177417123467264  1490603291757903872  0.818290  0.816621      1   \n",
       "3        1374177417123467264  1468148406491938816  0.816224  0.815418      1   \n",
       "4        1374177417123467264  1470307844552261632  0.802496  0.807428      1   \n",
       "...                      ...                  ...       ...       ...    ...   \n",
       "4744800  1648527394191052802  1466315796216152064  0.581455  0.598333      6   \n",
       "4744801  1648527394191052802  1472845935146041344  0.580339  0.597683      6   \n",
       "4744802  1648527394191052802  1470284037246550016  0.535507  0.598223      6   \n",
       "4744803  1648527394191052802  1645385086935367680  0.478026  0.589088      6   \n",
       "4744804  1648527394191052802  1648345891960127488  0.406044  0.475809      6   \n",
       "\n",
       "         round_1  \n",
       "0              0  \n",
       "1              0  \n",
       "2              0  \n",
       "3              0  \n",
       "4              0  \n",
       "...          ...  \n",
       "4744800        0  \n",
       "4744801        0  \n",
       "4744802        0  \n",
       "4744803        0  \n",
       "4744804        0  \n",
       "\n",
       "[4744805 rows x 6 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merged_data.loc[df_filtered.groupby(\"resumeId\")[\"data2\"].idxmax(),\"round_1\"] = 1\n",
    "merged_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "counts = merged_data.groupby(\"jobId\")['count'].max().to_dict()\n",
    "counts;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "def set_round_for_group2(df):\n",
    "    counts = df.groupby(\"jobId\")['count'].max().to_dict()\n",
    "    def set_round_for_group_(group):\n",
    "        count = counts[group[\"jobId\"].iloc[0]]\n",
    "        # print(\"--------------------\")\n",
    "        # print(count)\n",
    "        # print(\"满足要求的人\")\n",
    "        group = group.query(\"round_1 != 0\")\n",
    "        # print(group)\n",
    "        # print(\"--------------------\")\n",
    "        # print(\"\\n\")\n",
    "        if count <0 :\n",
    "            if len(group) !=0:\n",
    "                group.loc[group['jobId'].index[0]:group['jobId'].index[0]+1, \"round_1\"] = 2\n",
    "                group['count'] -=1\n",
    "            else:\n",
    "                pass\n",
    "        else:\n",
    "            if len(group) >= count:\n",
    "                group.loc[group['jobId'].index[0]:group['jobId'].index[0]+count-1, \"round_1\"] = 2\n",
    "                group['count'] -= count\n",
    "            else:\n",
    "                group[\"round_1\"] = 2\n",
    "                group[\"count\"] -= len(group)\n",
    "        return group\n",
    "    \n",
    "    res = df.groupby(\"jobId\").apply(set_round_for_group_)\n",
    "    \n",
    "    index = [i[1] for i in res.index]\n",
    "    df.loc[index,\"round_1\"] = res['round_1'].values             # 将结果返回到原来的矩阵上\n",
    "    \n",
    "    dic_ = dict(zip(res['jobId'].values.tolist(),res['count'].values.tolist()))\n",
    "    df.loc[df['jobId'].isin(dic_.keys()), 'count'] = df['jobId'].map(dic_)\n",
    "    return df\n",
    "merged_data = set_round_for_group2(merged_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>resumeId</th>\n",
       "      <th>data</th>\n",
       "      <th>data2</th>\n",
       "      <th>count</th>\n",
       "      <th>round_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1469590908960899072</td>\n",
       "      <td>0.836233</td>\n",
       "      <td>0.827064</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470745702312312832</td>\n",
       "      <td>0.834449</td>\n",
       "      <td>0.826026</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1490603291757903872</td>\n",
       "      <td>0.818290</td>\n",
       "      <td>0.816621</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1468148406491938816</td>\n",
       "      <td>0.816224</td>\n",
       "      <td>0.815418</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470307844552261632</td>\n",
       "      <td>0.802496</td>\n",
       "      <td>0.807428</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1466315796216152064</td>\n",
       "      <td>0.581455</td>\n",
       "      <td>0.598333</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1472845935146041344</td>\n",
       "      <td>0.580339</td>\n",
       "      <td>0.597683</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1470284037246550016</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1645385086935367680</td>\n",
       "      <td>0.478026</td>\n",
       "      <td>0.589088</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1648345891960127488</td>\n",
       "      <td>0.406044</td>\n",
       "      <td>0.475809</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       jobId             resumeId      data     data2  count  \\\n",
       "0        1374177417123467264  1469590908960899072  0.836233  0.827064      0   \n",
       "1        1374177417123467264  1470745702312312832  0.834449  0.826026      0   \n",
       "2        1374177417123467264  1490603291757903872  0.818290  0.816621      0   \n",
       "3        1374177417123467264  1468148406491938816  0.816224  0.815418      0   \n",
       "4        1374177417123467264  1470307844552261632  0.802496  0.807428      0   \n",
       "...                      ...                  ...       ...       ...    ...   \n",
       "4744800  1648527394191052802  1466315796216152064  0.581455  0.598333      6   \n",
       "4744801  1648527394191052802  1472845935146041344  0.580339  0.597683      6   \n",
       "4744802  1648527394191052802  1470284037246550016  0.535507  0.598223      6   \n",
       "4744803  1648527394191052802  1645385086935367680  0.478026  0.589088      6   \n",
       "4744804  1648527394191052802  1648345891960127488  0.406044  0.475809      6   \n",
       "\n",
       "         round_1  \n",
       "0              0  \n",
       "1              0  \n",
       "2              0  \n",
       "3              0  \n",
       "4              0  \n",
       "...          ...  \n",
       "4744800        0  \n",
       "4744801        0  \n",
       "4744802        0  \n",
       "4744803        0  \n",
       "4744804        0  \n",
       "\n",
       "[4744805 rows x 6 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merged_data['round_1'] = merged_data['round_1'].map(lambda x:0 if x==1 else x)\n",
    "merged_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>resumeId</th>\n",
       "      <th>data</th>\n",
       "      <th>data2</th>\n",
       "      <th>count</th>\n",
       "      <th>round_1</th>\n",
       "      <th>round_2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>1374177686322286592</td>\n",
       "      <td>1461534785997504512</td>\n",
       "      <td>0.743148</td>\n",
       "      <td>0.737194</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>1374177686322286592</td>\n",
       "      <td>1643560323032154112</td>\n",
       "      <td>0.664473</td>\n",
       "      <td>0.727093</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>1374177686322286592</td>\n",
       "      <td>1461530285551255552</td>\n",
       "      <td>0.660187</td>\n",
       "      <td>0.720808</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>1374177686322286592</td>\n",
       "      <td>1647012656068034560</td>\n",
       "      <td>0.568783</td>\n",
       "      <td>0.617591</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>1374177686322286592</td>\n",
       "      <td>1647579226406256640</td>\n",
       "      <td>0.560967</td>\n",
       "      <td>0.648733</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1466315796216152064</td>\n",
       "      <td>0.581455</td>\n",
       "      <td>0.598333</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1472845935146041344</td>\n",
       "      <td>0.580339</td>\n",
       "      <td>0.597683</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1470284037246550016</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1645385086935367680</td>\n",
       "      <td>0.478026</td>\n",
       "      <td>0.589088</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1648345891960127488</td>\n",
       "      <td>0.406044</td>\n",
       "      <td>0.475809</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4679036 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       jobId             resumeId      data     data2  count  \\\n",
       "37       1374177686322286592  1461534785997504512  0.743148  0.737194      1   \n",
       "38       1374177686322286592  1643560323032154112  0.664473  0.727093      1   \n",
       "39       1374177686322286592  1461530285551255552  0.660187  0.720808      1   \n",
       "40       1374177686322286592  1647012656068034560  0.568783  0.617591      1   \n",
       "41       1374177686322286592  1647579226406256640  0.560967  0.648733      1   \n",
       "...                      ...                  ...       ...       ...    ...   \n",
       "4744800  1648527394191052802  1466315796216152064  0.581455  0.598333      6   \n",
       "4744801  1648527394191052802  1472845935146041344  0.580339  0.597683      6   \n",
       "4744802  1648527394191052802  1470284037246550016  0.535507  0.598223      6   \n",
       "4744803  1648527394191052802  1645385086935367680  0.478026  0.589088      6   \n",
       "4744804  1648527394191052802  1648345891960127488  0.406044  0.475809      6   \n",
       "\n",
       "         round_1  round_2  \n",
       "37             0        0  \n",
       "38             2        0  \n",
       "39             0        0  \n",
       "40             0        0  \n",
       "41             0        0  \n",
       "...          ...      ...  \n",
       "4744800        0        0  \n",
       "4744801        0        0  \n",
       "4744802        0        0  \n",
       "4744803        0        0  \n",
       "4744804        0        0  \n",
       "\n",
       "[4679036 rows x 7 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merged_data['round_2'] = 0\n",
    "remaining_job_slots = merged_data.groupby(\"jobId\")[\"count\"].first()\n",
    "df_filtered = merged_data[merged_data[\"jobId\"].map(remaining_job_slots) != 0]\n",
    "df_filtered"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>resumeId</th>\n",
       "      <th>data</th>\n",
       "      <th>data2</th>\n",
       "      <th>count</th>\n",
       "      <th>round_1</th>\n",
       "      <th>round_2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1469590908960899072</td>\n",
       "      <td>0.836233</td>\n",
       "      <td>0.827064</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470745702312312832</td>\n",
       "      <td>0.834449</td>\n",
       "      <td>0.826026</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1490603291757903872</td>\n",
       "      <td>0.818290</td>\n",
       "      <td>0.816621</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1468148406491938816</td>\n",
       "      <td>0.816224</td>\n",
       "      <td>0.815418</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470307844552261632</td>\n",
       "      <td>0.802496</td>\n",
       "      <td>0.807428</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1466315796216152064</td>\n",
       "      <td>0.581455</td>\n",
       "      <td>0.598333</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1472845935146041344</td>\n",
       "      <td>0.580339</td>\n",
       "      <td>0.597683</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1470284037246550016</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1645385086935367680</td>\n",
       "      <td>0.478026</td>\n",
       "      <td>0.589088</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1648345891960127488</td>\n",
       "      <td>0.406044</td>\n",
       "      <td>0.475809</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       jobId             resumeId      data     data2  count  \\\n",
       "0        1374177417123467264  1469590908960899072  0.836233  0.827064      0   \n",
       "1        1374177417123467264  1470745702312312832  0.834449  0.826026      0   \n",
       "2        1374177417123467264  1490603291757903872  0.818290  0.816621      0   \n",
       "3        1374177417123467264  1468148406491938816  0.816224  0.815418      0   \n",
       "4        1374177417123467264  1470307844552261632  0.802496  0.807428      0   \n",
       "...                      ...                  ...       ...       ...    ...   \n",
       "4744800  1648527394191052802  1466315796216152064  0.581455  0.598333      6   \n",
       "4744801  1648527394191052802  1472845935146041344  0.580339  0.597683      6   \n",
       "4744802  1648527394191052802  1470284037246550016  0.535507  0.598223      6   \n",
       "4744803  1648527394191052802  1645385086935367680  0.478026  0.589088      6   \n",
       "4744804  1648527394191052802  1648345891960127488  0.406044  0.475809      6   \n",
       "\n",
       "         round_1  round_2  \n",
       "0              0        0  \n",
       "1              0        0  \n",
       "2              0        0  \n",
       "3              0        0  \n",
       "4              0        0  \n",
       "...          ...      ...  \n",
       "4744800        0        0  \n",
       "4744801        0        0  \n",
       "4744802        0        0  \n",
       "4744803        0        0  \n",
       "4744804        0        0  \n",
       "\n",
       "[4744805 rows x 7 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merged_data.loc[df_filtered.groupby(\"resumeId\")[\"data2\"].idxmax(),\"round_2\"] = 1\n",
    "merged_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "def set_round_for_group2(df):\n",
    "    counts = df.groupby(\"jobId\")['count'].max().to_dict()\n",
    "    def set_round_for_group_(group):\n",
    "        count = counts[group[\"jobId\"].iloc[0]]\n",
    "        # print(\"--------------------\")\n",
    "        # print(count)\n",
    "        # print(\"满足要求的人\")\n",
    "        group = group.query(\"round_2 != 0\")\n",
    "        group = group.query(\"round_1 != 2\")\n",
    "        # print(group)\n",
    "        # print(\"--------------------\")\n",
    "        # print(\"\\n\")\n",
    "        if count <0 :\n",
    "            if len(group) !=0:\n",
    "                group.loc[group['jobId'].index[0]:group['jobId'].index[0]+1, \"round_2\"] = 2\n",
    "                group['count'] -=1\n",
    "            else:\n",
    "                pass\n",
    "        else:\n",
    "            if len(group) !=0:\n",
    "                if len(group) >= count:\n",
    "                    group.loc[group['jobId'].index[0]:group['jobId'].index[0]+count-1, \"round_2\"] = 2\n",
    "                    group['count'] -= count\n",
    "                else:\n",
    "                    group[\"round_2\"] = 2\n",
    "                    group[\"count\"] -= len(group)\n",
    "            else:\n",
    "                pass\n",
    "        return group\n",
    "    \n",
    "    res = df.groupby(\"jobId\").apply(set_round_for_group_)\n",
    "    \n",
    "    index = [i[1] for i in res.index]\n",
    "    df.loc[index,\"round_2\"] = res['round_2'].values             # 将结果返回到原来的矩阵上\n",
    "    \n",
    "    dic_ = dict(zip(res['jobId'].values.tolist(),res['count'].values.tolist()))\n",
    "    df.loc[df['jobId'].isin(dic_.keys()), 'count'] = df['jobId'].map(dic_)\n",
    "    return df\n",
    "merged_data = set_round_for_group2(merged_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    4736524\n",
       "1       8245\n",
       "2         36\n",
       "Name: round_2, dtype: int64"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merged_data['round_2'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>resumeId</th>\n",
       "      <th>data</th>\n",
       "      <th>data2</th>\n",
       "      <th>count</th>\n",
       "      <th>round_1</th>\n",
       "      <th>round_2</th>\n",
       "      <th>round_3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1469590908960899072</td>\n",
       "      <td>0.836233</td>\n",
       "      <td>0.827064</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470745702312312832</td>\n",
       "      <td>0.834449</td>\n",
       "      <td>0.826026</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1490603291757903872</td>\n",
       "      <td>0.818290</td>\n",
       "      <td>0.816621</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1468148406491938816</td>\n",
       "      <td>0.816224</td>\n",
       "      <td>0.815418</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470307844552261632</td>\n",
       "      <td>0.802496</td>\n",
       "      <td>0.807428</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1466315796216152064</td>\n",
       "      <td>0.581455</td>\n",
       "      <td>0.598333</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1472845935146041344</td>\n",
       "      <td>0.580339</td>\n",
       "      <td>0.597683</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1470284037246550016</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1645385086935367680</td>\n",
       "      <td>0.478026</td>\n",
       "      <td>0.589088</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1648345891960127488</td>\n",
       "      <td>0.406044</td>\n",
       "      <td>0.475809</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       jobId             resumeId      data     data2  count  \\\n",
       "0        1374177417123467264  1469590908960899072  0.836233  0.827064      0   \n",
       "1        1374177417123467264  1470745702312312832  0.834449  0.826026      0   \n",
       "2        1374177417123467264  1490603291757903872  0.818290  0.816621      0   \n",
       "3        1374177417123467264  1468148406491938816  0.816224  0.815418      0   \n",
       "4        1374177417123467264  1470307844552261632  0.802496  0.807428      0   \n",
       "...                      ...                  ...       ...       ...    ...   \n",
       "4744800  1648527394191052802  1466315796216152064  0.581455  0.598333      6   \n",
       "4744801  1648527394191052802  1472845935146041344  0.580339  0.597683      6   \n",
       "4744802  1648527394191052802  1470284037246550016  0.535507  0.598223      6   \n",
       "4744803  1648527394191052802  1645385086935367680  0.478026  0.589088      6   \n",
       "4744804  1648527394191052802  1648345891960127488  0.406044  0.475809      6   \n",
       "\n",
       "         round_1  round_2  round_3  \n",
       "0              0        0        0  \n",
       "1              0        0        0  \n",
       "2              0        0        0  \n",
       "3              0        0        0  \n",
       "4              0        0        0  \n",
       "...          ...      ...      ...  \n",
       "4744800        0        0        0  \n",
       "4744801        0        0        0  \n",
       "4744802        0        0        0  \n",
       "4744803        0        0        0  \n",
       "4744804        0        0        0  \n",
       "\n",
       "[4744805 rows x 8 columns]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merged_data['round_2'] = merged_data['round_2'].map(lambda x:0 if x==1 else x)\n",
    "merged_data['round_3'] = 0\n",
    "remaining_job_slots = merged_data.groupby(\"jobId\")[\"count\"].first()\n",
    "df_filtered = merged_data[merged_data[\"jobId\"].map(remaining_job_slots) != 0]\n",
    "merged_data.loc[df_filtered.groupby(\"resumeId\")[\"data2\"].idxmax(),\"round_3\"] = 1\n",
    "merged_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "def set_round_for_group2(df):\n",
    "    counts = df.groupby(\"jobId\")['count'].max().to_dict()\n",
    "    def set_round_for_group_(group):\n",
    "        count = counts[group[\"jobId\"].iloc[0]]\n",
    "        # print(\"--------------------\")\n",
    "        # print(count)\n",
    "        # print(\"满足要求的人\")\n",
    "        group = group.query(\"round_3 != 0\")\n",
    "        group = group.query(\"round_1 != 2\")\n",
    "        group = group.query(\"round_2 != 2\")\n",
    "        # print(group)\n",
    "        # print(\"--------------------\")\n",
    "        # print(\"\\n\")\n",
    "        if count <0 :\n",
    "            if len(group) !=0:\n",
    "                group.loc[group['jobId'].index[0]:group['jobId'].index[0]+1, \"round_3\"] = 2\n",
    "                group['count'] -=1\n",
    "            else:\n",
    "                pass\n",
    "        else:\n",
    "            if len(group) !=0:\n",
    "                if len(group) >= count:\n",
    "                    group.loc[group['jobId'].index[0]:group['jobId'].index[0]+count-1, \"round_3\"] = 2\n",
    "                    group['count'] -= count\n",
    "                else:\n",
    "                    group[\"round_3\"] = 2\n",
    "                    group[\"count\"] -= len(group)\n",
    "            else:\n",
    "                pass\n",
    "        return group\n",
    "    \n",
    "    res = df.groupby(\"jobId\").apply(set_round_for_group_)\n",
    "    \n",
    "    index = [i[1] for i in res.index]\n",
    "    df.loc[index,\"round_3\"] = res['round_3'].values             # 将结果返回到原来的矩阵上\n",
    "    \n",
    "    dic_ = dict(zip(res['jobId'].values.tolist(),res['count'].values.tolist()))\n",
    "    df.loc[df['jobId'].isin(dic_.keys()), 'count'] = df['jobId'].map(dic_)\n",
    "    return df\n",
    "merged_data = set_round_for_group2(merged_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>resumeId</th>\n",
       "      <th>data</th>\n",
       "      <th>data2</th>\n",
       "      <th>count</th>\n",
       "      <th>round_1</th>\n",
       "      <th>round_2</th>\n",
       "      <th>round_3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1469590908960899072</td>\n",
       "      <td>0.836233</td>\n",
       "      <td>0.827064</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470745702312312832</td>\n",
       "      <td>0.834449</td>\n",
       "      <td>0.826026</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1490603291757903872</td>\n",
       "      <td>0.818290</td>\n",
       "      <td>0.816621</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1468148406491938816</td>\n",
       "      <td>0.816224</td>\n",
       "      <td>0.815418</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1374177417123467264</td>\n",
       "      <td>1470307844552261632</td>\n",
       "      <td>0.802496</td>\n",
       "      <td>0.807428</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744800</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1466315796216152064</td>\n",
       "      <td>0.581455</td>\n",
       "      <td>0.598333</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744801</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1472845935146041344</td>\n",
       "      <td>0.580339</td>\n",
       "      <td>0.597683</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744802</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1470284037246550016</td>\n",
       "      <td>0.535507</td>\n",
       "      <td>0.598223</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744803</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1645385086935367680</td>\n",
       "      <td>0.478026</td>\n",
       "      <td>0.589088</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4744804</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>1648345891960127488</td>\n",
       "      <td>0.406044</td>\n",
       "      <td>0.475809</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4744805 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       jobId             resumeId      data     data2  count  \\\n",
       "0        1374177417123467264  1469590908960899072  0.836233  0.827064      0   \n",
       "1        1374177417123467264  1470745702312312832  0.834449  0.826026      0   \n",
       "2        1374177417123467264  1490603291757903872  0.818290  0.816621      0   \n",
       "3        1374177417123467264  1468148406491938816  0.816224  0.815418      0   \n",
       "4        1374177417123467264  1470307844552261632  0.802496  0.807428      0   \n",
       "...                      ...                  ...       ...       ...    ...   \n",
       "4744800  1648527394191052802  1466315796216152064  0.581455  0.598333      6   \n",
       "4744801  1648527394191052802  1472845935146041344  0.580339  0.597683      6   \n",
       "4744802  1648527394191052802  1470284037246550016  0.535507  0.598223      6   \n",
       "4744803  1648527394191052802  1645385086935367680  0.478026  0.589088      6   \n",
       "4744804  1648527394191052802  1648345891960127488  0.406044  0.475809      6   \n",
       "\n",
       "         round_1  round_2  round_3  \n",
       "0              0        0        0  \n",
       "1              0        0        0  \n",
       "2              0        0        0  \n",
       "3              0        0        0  \n",
       "4              0        0        0  \n",
       "...          ...      ...      ...  \n",
       "4744800        0        0        0  \n",
       "4744801        0        0        0  \n",
       "4744802        0        0        0  \n",
       "4744803        0        0        0  \n",
       "4744804        0        0        0  \n",
       "\n",
       "[4744805 rows x 8 columns]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merged_data"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当n=2时\n",
    "if n>1:  \n",
    "    group = group.query(\"round_1 != 2\")\n",
    "\n",
    "当n=3时：\n",
    "if n>1:  \n",
    "    group = group.query(\"round_1 != 2\")\n",
    "    group = group.query(\"round_2 != 2\")\n",
    "\n",
    "当n=4时：\n",
    "if n>1:  \n",
    "    group = group.query(\"round_1 != 2\")\n",
    "    group = group.query(\"round_2 != 2\")\n",
    "    group = group.query(\"round_3 != 2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'(round_1 !=2) | (round_2 !=2)'"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "query_str = \"\"\n",
    "for i in range(1,3):\n",
    "    query_str += f\"(round_{i} !=2) | \"\n",
    "query_str[:-3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    4736524\n",
       "1       8249\n",
       "2         32\n",
       "Name: round_3, dtype: int64"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "while n<3:\n",
    "    n = 1\n",
    "    new_columns = merged_data[f\"round_{n}\"]\n",
    "    remaining_job_slots = merged_data.groupby(\"jobId\")[\"count\"].first()\n",
    "    df_filtered = merged_data[merged_data[\"jobId\"].map(remaining_job_slots) != 0]\n",
    "    merged_data.loc[df_filtered.groupby(\"resumeId\")[\"data2\"].idxmax(),new_columns] = 1\n",
    "    merged_data\n",
    "    \n",
    "    def set_round_for_group2(df):\n",
    "        counts = df.groupby(\"jobId\")['count'].max().to_dict()\n",
    "        def set_round_for_group_(group):\n",
    "            count = counts[group[\"jobId\"].iloc[0]]\n",
    "            # print(\"--------------------\")\n",
    "            # print(count)\n",
    "            # print(\"满足要求的人\")\n",
    "            group = group.query(f\"{new_columns} != 0\")\n",
    "            if n>1:  \n",
    "                query_str = \"\"\n",
    "                for i in range(1,3):\n",
    "                    query_str += f\"(round_{i} !=2) | \"\n",
    "                query_str = query_str[:-3]\n",
    "                group = group.query(query_str)\n",
    "            # print(group)\n",
    "            # print(\"--------------------\")\n",
    "            # print(\"\\n\")\n",
    "            if count <0 :\n",
    "                if len(group) !=0:\n",
    "                    group.loc[group['jobId'].index[0]:group['jobId'].index[0]+1, new_columns] = 2\n",
    "                    group['count'] -=1\n",
    "                else:\n",
    "                    pass\n",
    "            else:\n",
    "                if len(group) !=0:\n",
    "                    if len(group) >= count:\n",
    "                        group.loc[group['jobId'].index[0]:group['jobId'].index[0]+count-1, new_columns] = 2\n",
    "                        group['count'] -= count\n",
    "                    else:\n",
    "                        group[new_columns] = 2\n",
    "                        group[\"count\"] -= len(group)\n",
    "                else:\n",
    "                    pass\n",
    "            return group\n",
    "        \n",
    "        res = df.groupby(\"jobId\").apply(set_round_for_group_)\n",
    "        \n",
    "        index = [i[1] for i in res.index]\n",
    "        df.loc[index,new_columns] = res[new_columns].values             # 将结果返回到原来的矩阵上\n",
    "        \n",
    "        dic_ = dict(zip(res['jobId'].values.tolist(),res['count'].values.tolist()))\n",
    "        df.loc[df['jobId'].isin(dic_.keys()), 'count'] = df['jobId'].map(dic_)\n",
    "        return df\n",
    "\n",
    "    merged_data = set_round_for_group2(merged_data)\n",
    "    merged_data[new_columns] = merged_data[new_columns].map(lambda x:0 if x==1 else x)\n",
    "    print(melted_df[new_columns].value_counts())\n",
    "    n+=1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobID</th>\n",
       "      <th>peopleID</th>\n",
       "      <th>data1</th>\n",
       "      <th>data2</th>\n",
       "      <th>jobnum</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>1365879387125688560</td>\n",
       "      <td>0.87</td>\n",
       "      <td>0.91</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>5761579356823138358</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.91</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>1259734889723772246</td>\n",
       "      <td>0.72</td>\n",
       "      <td>0.90</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>5761579356823138358</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.83</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>3655671218465889104</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.86</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>1979608497675601812</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.78</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>1368492782664320473</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.88</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1897843625703822038</td>\n",
       "      <td>1368492782664320478</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.88</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 jobID             peopleID  data1  data2  jobnum\n",
       "0  1461579387123138560  1365879387125688560   0.87   0.91       1\n",
       "1  1461579387123138560  5761579356823138358   0.81   0.91       1\n",
       "2  1461579387123138560  1259734889723772246   0.72   0.90       1\n",
       "3  1897843625703822037  5761579356823138358   0.84   0.83       2\n",
       "4  1897843625703822037  3655671218465889104   0.80   0.86       2\n",
       "5  1897843625703822037  1979608497675601812   0.76   0.78       2\n",
       "6  1897843625703822037  1368492782664320473   0.71   0.88       2\n",
       "7  1897843625703822038  1368492782664320478   0.71   0.88       2"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "data = [\n",
    "    (1461579387123138560, 1365879387125688560, 0.87, 0.91, 1),\n",
    "    (1461579387123138560, 5761579356823138358, 0.81, 0.91, 1),\n",
    "    (1461579387123138560, 1259734889723772246, 0.72, 0.90, 1),\n",
    "    (1897843625703822037, 5761579356823138358, 0.84, 0.83, 2),\n",
    "    (1897843625703822037, 3655671218465889104, 0.80, 0.86, 2),\n",
    "    (1897843625703822037, 1979608497675601812, 0.76, 0.78, 2),\n",
    "    (1897843625703822037, 1368492782664320473, 0.71, 0.88, 2),\n",
    "    (1897843625703822038, 1368492782664320478, 0.71, 0.88, 2),\n",
    "]\n",
    "\n",
    "columns = [\"jobID\", \"peopleID\", \"data1\", \"data2\", \"jobnum\"]\n",
    "df = pd.DataFrame(data, columns=columns)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobID</th>\n",
       "      <th>peopleID</th>\n",
       "      <th>data1</th>\n",
       "      <th>data2</th>\n",
       "      <th>jobnum</th>\n",
       "      <th>round_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>1365879387125688560</td>\n",
       "      <td>0.87</td>\n",
       "      <td>0.91</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>5761579356823138358</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.91</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>1259734889723772246</td>\n",
       "      <td>0.72</td>\n",
       "      <td>0.90</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>5761579356823138358</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.83</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>3655671218465889104</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.86</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>1979608497675601812</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.78</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>1368492782664320473</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.88</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1897843625703822038</td>\n",
       "      <td>1368492782664320478</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.88</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 jobID             peopleID  data1  data2  jobnum  round_1\n",
       "0  1461579387123138560  1365879387125688560   0.87   0.91       1        0\n",
       "1  1461579387123138560  5761579356823138358   0.81   0.91       1        0\n",
       "2  1461579387123138560  1259734889723772246   0.72   0.90       1        0\n",
       "3  1897843625703822037  5761579356823138358   0.84   0.83       2        0\n",
       "4  1897843625703822037  3655671218465889104   0.80   0.86       2        0\n",
       "5  1897843625703822037  1979608497675601812   0.76   0.78       2        0\n",
       "6  1897843625703822037  1368492782664320473   0.71   0.88       2        0\n",
       "7  1897843625703822038  1368492782664320478   0.71   0.88       2        0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"round_1\"] = 0\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobID</th>\n",
       "      <th>peopleID</th>\n",
       "      <th>data1</th>\n",
       "      <th>data2</th>\n",
       "      <th>jobnum</th>\n",
       "      <th>round_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>1365879387125688560</td>\n",
       "      <td>0.87</td>\n",
       "      <td>0.91</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>5761579356823138358</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.91</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>1259734889723772246</td>\n",
       "      <td>0.72</td>\n",
       "      <td>0.90</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>5761579356823138358</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.83</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>3655671218465889104</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.86</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>1979608497675601812</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.78</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>1368492782664320473</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.88</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1897843625703822038</td>\n",
       "      <td>1368492782664320478</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.88</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 jobID             peopleID  data1  data2  jobnum  round_1\n",
       "0  1461579387123138560  1365879387125688560   0.87   0.91       1        0\n",
       "1  1461579387123138560  5761579356823138358   0.81   0.91       1        0\n",
       "2  1461579387123138560  1259734889723772246   0.72   0.90       1        0\n",
       "3  1897843625703822037  5761579356823138358   0.84   0.83       2        0\n",
       "4  1897843625703822037  3655671218465889104   0.80   0.86       2        0\n",
       "5  1897843625703822037  1979608497675601812   0.76   0.78       2        0\n",
       "6  1897843625703822037  1368492782664320473   0.71   0.88       2        0\n",
       "7  1897843625703822038  1368492782664320478   0.71   0.88       2        0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 抽取大于0的岗位\n",
    "remaining_job_slots = df.groupby(\"jobID\")[\"jobnum\"].first()\n",
    "df_filtered = df[df[\"jobID\"].map(remaining_job_slots) > 0]\n",
    "df_filtered"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobID</th>\n",
       "      <th>peopleID</th>\n",
       "      <th>data1</th>\n",
       "      <th>data2</th>\n",
       "      <th>jobnum</th>\n",
       "      <th>round_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>1365879387125688560</td>\n",
       "      <td>0.87</td>\n",
       "      <td>0.91</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>5761579356823138358</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.91</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>1259734889723772246</td>\n",
       "      <td>0.72</td>\n",
       "      <td>0.90</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>5761579356823138358</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.83</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>3655671218465889104</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.86</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>1979608497675601812</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.78</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>1368492782664320473</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.88</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1897843625703822038</td>\n",
       "      <td>1368492782664320478</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.88</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 jobID             peopleID  data1  data2  jobnum  round_1\n",
       "0  1461579387123138560  1365879387125688560   0.87   0.91       1        1\n",
       "1  1461579387123138560  5761579356823138358   0.81   0.91       1        1\n",
       "2  1461579387123138560  1259734889723772246   0.72   0.90       1        1\n",
       "3  1897843625703822037  5761579356823138358   0.84   0.83       2        0\n",
       "4  1897843625703822037  3655671218465889104   0.80   0.86       2        1\n",
       "5  1897843625703822037  1979608497675601812   0.76   0.78       2        1\n",
       "6  1897843625703822037  1368492782664320473   0.71   0.88       2        1\n",
       "7  1897843625703822038  1368492782664320478   0.71   0.88       2        1"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df_filtered.groupby(\"peopleID\")[\"data2\"].idxmax(),\"round_1\"] = 1\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                 jobID             peopleID  data1  data2  jobnum  round_1\n",
      "0  1461579387123138560  1365879387125688560   0.87   0.91       0        2\n",
      "1  1461579387123138560  5761579356823138358   0.81   0.91       0        1\n",
      "2  1461579387123138560  1259734889723772246   0.72   0.90       0        1\n",
      "                 jobID             peopleID  data1  data2  jobnum  round_1\n",
      "4  1897843625703822037  3655671218465889104   0.80   0.86       0        2\n",
      "5  1897843625703822037  1979608497675601812   0.76   0.78       0        2\n",
      "6  1897843625703822037  1368492782664320473   0.71   0.88       0        1\n",
      "                 jobID             peopleID  data1  data2  jobnum  round_1\n",
      "7  1897843625703822038  1368492782664320478   0.71   0.88       1        2\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobID</th>\n",
       "      <th>peopleID</th>\n",
       "      <th>data1</th>\n",
       "      <th>data2</th>\n",
       "      <th>jobnum</th>\n",
       "      <th>round_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>1365879387125688560</td>\n",
       "      <td>0.87</td>\n",
       "      <td>0.91</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>5761579356823138358</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.91</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1461579387123138560</td>\n",
       "      <td>1259734889723772246</td>\n",
       "      <td>0.72</td>\n",
       "      <td>0.90</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>5761579356823138358</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.83</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>3655671218465889104</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.86</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>1979608497675601812</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.78</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1897843625703822037</td>\n",
       "      <td>1368492782664320473</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.88</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1897843625703822038</td>\n",
       "      <td>1368492782664320478</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.88</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 jobID             peopleID  data1  data2  jobnum  round_1\n",
       "0  1461579387123138560  1365879387125688560   0.87   0.91       0        2\n",
       "1  1461579387123138560  5761579356823138358   0.81   0.91       0        1\n",
       "2  1461579387123138560  1259734889723772246   0.72   0.90       0        1\n",
       "3  1897843625703822037  5761579356823138358   0.84   0.83       0        0\n",
       "4  1897843625703822037  3655671218465889104   0.80   0.86       0        2\n",
       "5  1897843625703822037  1979608497675601812   0.76   0.78       0        2\n",
       "6  1897843625703822037  1368492782664320473   0.71   0.88       0        1\n",
       "7  1897843625703822038  1368492782664320478   0.71   0.88       1        2"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "def set_round_for_group2():\n",
    "    counts = df.groupby(\"jobID\")['jobnum'].max().to_dict()\n",
    "    def set_round_for_group_(group):\n",
    "        count = counts[group[\"jobID\"].iloc[0]]\n",
    "        group = group.query(\"round_1 != 0\")\n",
    "        if len(group) >= count:\n",
    "            group.loc[group['jobID'].index[0]:group['jobID'].index[0]+count-1, \"round_1\"] = 2\n",
    "            group['jobnum'] -= count\n",
    "        else:\n",
    "            group[\"round_1\"] = 2\n",
    "            group[\"jobnum\"] -= len(group)\n",
    "        print(group)\n",
    "        return group\n",
    "    res = df.groupby(\"jobID\").apply(set_round_for_group_)\n",
    "    index = [i[1] for i in res.index]\n",
    "    df.loc[index,\"round_1\"] = res['round_1'].values\n",
    "    dic_ = dict(zip(res['jobID'].values.tolist(),res['jobnum'].values.tolist()))\n",
    "    df.loc[df['jobID'].isin(dic_.keys()), 'jobnum'] = df['jobID'].map(dic_)\n",
    "    return df\n",
    "set_round_for_group2()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
